package br.edu.utfpr.backuptools.BackupTools.view.action.backup;

import br.edu.utfpr.backuptools.BackupTools.controller.ControladorBackupImpl;
import br.edu.utfpr.backuptools.BackupTools.controller.interfaces.ControladorBackup;
import br.edu.utfpr.backuptools.BackupTools.controller.validator.BackupValidator;
import br.edu.utfpr.backuptools.BackupTools.controller.validator.RetornoValidacao;
import br.edu.utfpr.backuptools.BackupTools.model.dao.DaoBackupImpl;
import br.edu.utfpr.backuptools.BackupTools.model.dao.interfaces.DaoBackup;
import br.edu.utfpr.backuptools.BackupTools.model.pojo.Backup;
import br.edu.utfpr.backuptools.BackupTools.view.action.AbstractAction;

public class SalvarBackupAction extends AbstractAction<Backup> {

	DaoBackup dao = new DaoBackupImpl();
	ControladorBackup controlador = new ControladorBackupImpl(dao,new BackupValidator());
	
	@Override
	public RetornoValidacao execute(Backup bean) {
		try {
			bean.setOrigem(bean.getOrigem().replaceAll("\\\\", "/"));
			bean.setDestino(bean.getDestino().replaceAll("\\\\", "/"));
			
			RetornoValidacao rv = controlador.save(bean);
			return rv;
		} catch (Exception e) {
			e.printStackTrace();
			return new RetornoValidacao(false, "Desculpe, ocorreu um erro desconhecido ao salvar o backup");
		}
	}

}
